package com.golden.procedure.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.golden.procedure.domain.OrderProductDO;
import com.golden.procedure.domain.QueryRequest;
import com.golden.procedure.domain.SingleRequest;
import com.golden.procedure.domain.WorkAttachmentAccountDO;
import com.golden.procedure.domain.WorkAttachmentDO;
import com.golden.procedure.domain.WorkCommentDO;
import com.golden.procedure.domain.WorkCommissionDO;
import com.golden.procedure.domain.WorkDesignOrderDO;
import com.golden.procedure.domain.WorkOrderPickDO;
import com.golden.procedure.domain.WorkPhotoPickDO;
import com.golden.procedure.domain.WorkPhotoProductDO;
import com.golden.procedure.domain.WorkPickDetailDO;
import com.golden.procedure.query.WorkAttachmentQueryDO;
import com.golden.procedure.result.PageResponse;
import com.golden.procedure.result.ResultDO;
import com.golden.procedure.result.SingleResponse;
import com.golden.procedure.service.IWorkAttachmentService;
import com.golden.procedure.service.IWorkDesignOrderService;
import com.golden.procedure.service.IWorkOrderPickService;
import com.golden.procedure.service.IWorkPhotoProductService;
import com.golden.procedure.util.BonConstant;
import com.golden.procedure.util.EncryptedUtil;
import com.golden.procedure.util.HttpStatus;
import com.google.gson.Gson;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 照片、选片入册、制作单相关管理 <b>Description:</b><br>
 * 
 * @author Reading.Reagan</a>
 * @version 1.0
 * @Note <b>ProjectName:</b> procedure <br>
 *       <b>PackageName:</b> com.golden.procedure.controller <br>
 *       <b>ClassName:</b> WorkAttachmentController <br>
 *       <b>Date:</b> 2018年10月22日 下午6:30:44
 */
@RestController
@RequestMapping(value = "/api/photo") 
public class WorkAttachmentController extends BaseController {

	@Autowired
	IWorkOrderPickService workOrderPickService;
	@Autowired
	IWorkAttachmentService workAttachmentService;
	@Autowired
	IWorkPhotoProductService workPhotoProductService;
	@Autowired
	IWorkDesignOrderService workDesignOrderService;

	public static String encodePhotoProductPage(PageResponse<WorkPhotoProductDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeProductPage(PageResponse<OrderProductDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodePage(PageResponse<WorkAttachmentDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeDetailPage(PageResponse<WorkPickDetailDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeCommentPage(PageResponse<WorkCommentDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeCommissionPage(PageResponse<WorkCommissionDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeObject(SingleResponse<WorkAttachmentDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodePickObject(SingleResponse<WorkOrderPickDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeDesignObject(SingleResponse<WorkDesignOrderDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodePhotoPickObject(SingleResponse<WorkPhotoPickDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeAccountObject(SingleResponse<WorkAttachmentAccountDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeDetailObject(SingleResponse<WorkPickDetailDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	@ApiOperation(value = "导入拍摄照片", notes = "导入拍摄照片入库")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workPhotographyID", value = "拍摄记录ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "groupID", value = "文件组ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "source", value = "片源", required = true, dataType = "Integer") })
	@RequestMapping(value = "/upload.json", method = RequestMethod.POST)
	public String upload(@RequestBody SingleRequest<WorkAttachmentDO> request) {

		WorkAttachmentDO domain = request.getData();

		SingleResponse<WorkAttachmentDO> response = new SingleResponse<WorkAttachmentDO>();
		ResultDO resultDO = workAttachmentService.test(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "查询上传的照片", notes = "查询上传的照片")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workPhotographyID", value = "拍摄记录ID", required = true, dataType = "Integer") })
	@RequestMapping(value = "/queryUpload.json", method = RequestMethod.POST)
	public String queryUpload(@RequestBody QueryRequest<WorkAttachmentQueryDO> request) {

		// {"data": {"workOrderID":3,"workPhotographyID":13, "pageNO":1,
		// "pageRows":3},
		// "version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkAttachmentQueryDO query = request.getData();
		// 类型：照片
		query.setAttachmentType(BonConstant.ATTACHMENT_TYPE_PHOTO);
		if (query.getPageRows() > 0) {
			query.setPage(true);
		}

		PageResponse<WorkAttachmentDO> response = new PageResponse<WorkAttachmentDO>();
		ResultDO resultDO = workAttachmentService.query(query);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((List<WorkAttachmentDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
			if (query.isPage()) {
				response.setTotal((int) resultDO.getModel(ResultDO.SECOND_MODEL_KEY));
			}
		} else {
			// 查询失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodePage(response, PLANINTEXT);
	}

	@ApiOperation(value = "查询待选照片", notes = "查询待选照片")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workPhotographyID", value = "拍摄记录ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "source", value = "片源：0-源片; 2-修调片", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "option", value = "0-本次/1-选中/2-未选/3-自备底片", required = false, dataType = "Integer") })
	@RequestMapping(value = "/query.json", method = RequestMethod.POST)
	public String query(@RequestBody QueryRequest<WorkAttachmentQueryDO> request) {

		// {"data": {"workOrderID":3,"workPhotographyID":13,"source":2,
		// "option":1, "pageNO":1, "pageRows":3},
		// "version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkAttachmentQueryDO query = request.getData();
		if (query.getPageRows() > 0) {
			query.setPage(true);
		}

		// 1. 根据条件设置查询条件 0-本次/1-选中/2-未选/3-自备底片
		if (query.getOption() == 0) {
			// 选片页面: 本次，包含制定片源及自备底片
			query.setSources(new Integer[] { query.getSource(), 3 });
			query.setSource(null);
		} else if (query.getOption() == 1) {
			// 选片页面: 已选，包含制定片源及自备底片中已被选中的照片
			query.setSources(new Integer[] { query.getSource(), 3 });
			query.setSource(null);
			query.setStatus(new Integer[] { 1 });
		} else if (query.getOption() == 2) {
			// 选片页面: 未选，包含制定片源及自备底片中未被选中的照片
			query.setSources(new Integer[] { query.getSource(), 3 });
			query.setSource(null);
			query.setStatus(new Integer[] { 0 });
		} else if (query.getOption() == 3) {
			// 选片页面: 自备，包含所有自备底片
			query.setSource(3);
		}

		PageResponse<WorkAttachmentDO> response = new PageResponse<WorkAttachmentDO>();
		ResultDO resultDO = workPhotoProductService.queryPick(query);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((List<WorkAttachmentDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
			response.setTotal((int) resultDO.getModel(ResultDO.SECOND_MODEL_KEY));
			response.setCount((int) resultDO.getModel(ResultDO.THIRD_MODEL_KEY));
		} else {
			// 查询失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodePage(response, PLANINTEXT);
	}

	@ApiOperation(value = "删除照片", notes = "删除照片")
	@ApiImplicitParam(name = "workOrderID", value = "照片ids", required = true, dataType = "Integer[]")
	@RequestMapping(value = "/delete.json", method = RequestMethod.POST)
	public String delete(@RequestBody SingleRequest<WorkAttachmentDO> request) {

		WorkAttachmentDO domain = request.getData();

		SingleResponse<WorkAttachmentDO> response = new SingleResponse<WorkAttachmentDO>();
		ResultDO resultDO = workAttachmentService.delete(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "删除所有照片", notes = "删除所有照片")
	@ApiImplicitParam(name = "workPhotographyID", value = "拍摄记录ID", required = true, dataType = "Integer")
	@RequestMapping(value = "/deleteAll.json", method = RequestMethod.POST)
	public String deleteAll(@RequestBody SingleRequest<WorkAttachmentDO> request) {

		WorkAttachmentDO domain = request.getData();

		SingleResponse<WorkAttachmentDO> response = new SingleResponse<WorkAttachmentDO>();
		ResultDO resultDO = workAttachmentService.deleteAll(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "取消选中的照片", notes = "取消照片")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "照片id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "status", value = "照片状态：0-不选;1-选中", required = true, dataType = "Integer") })
	@RequestMapping(value = "/cancel.json", method = RequestMethod.POST)
	public String cancel(@RequestBody SingleRequest<WorkAttachmentDO> request) {

		WorkAttachmentDO domain = request.getData();
		// 取消选中
		domain.setStatus(BonConstant.STATUS_FALSE);

		SingleResponse<WorkAttachmentDO> response = new SingleResponse<WorkAttachmentDO>();
		ResultDO resultDO = workAttachmentService.setStatus(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "选片入册", notes = "选片入册")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "attachmentID", value = "照片id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workOrderPickID", value = "选片记录ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "comment", value = "照片制作备注", required = true, dataType = "String"),
			@ApiImplicitParam(name = "productList", value = "商品列表", required = true, dataType = "List<WorkPhotoProductDO>") })
	@RequestMapping(value = "/pickForProduct.json", method = RequestMethod.POST)
	public String pickForProduct(@RequestBody SingleRequest<WorkPhotoPickDO> request) {

		WorkPhotoPickDO domain = request.getData();

		SingleResponse<WorkAttachmentDO> response = new SingleResponse<WorkAttachmentDO>();
		ResultDO resultDO = workPhotoProductService.add(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "查看某个商品的入册照片", notes = "查看某个商品的入册照片")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderProductID", value = "订单商品ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "String") })
	@RequestMapping(value = "/queryPhotoProduct.json", method = RequestMethod.POST)
	public String queryPhotoProduct(@RequestBody QueryRequest<WorkAttachmentQueryDO> request) {

		WorkAttachmentQueryDO domain = request.getData();

		PageResponse<WorkPhotoProductDO> response = new PageResponse<WorkPhotoProductDO>();
		ResultDO resultDO = workPhotoProductService.query(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((List<WorkPhotoProductDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
			response.setTotal((int) resultDO.getModel(ResultDO.SECOND_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodePhotoProductPage(response, PLANINTEXT);
	}

	@ApiOperation(value = "入册照片设为扉页", notes = "入册照片设为扉页")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "入册id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "String") })
	@RequestMapping(value = "/setCover.json", method = RequestMethod.POST)
	public String setCover(@RequestBody SingleRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();

		SingleResponse<WorkAttachmentDO> response = new SingleResponse<WorkAttachmentDO>();
		ResultDO resultDO = workPhotoProductService.setCover(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "照片数据统计接口", notes = "照片数据统计接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "source", value = "片源:0-源片;2-修调片;", required = true, dataType = "Integer") })
	@RequestMapping(value = "/accountPick.json", method = RequestMethod.POST)
	public String accountPick(@RequestBody SingleRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();

		SingleResponse<WorkAttachmentAccountDO> response = new SingleResponse<WorkAttachmentAccountDO>();
		ResultDO resultDO = workAttachmentService.account(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((WorkAttachmentAccountDO) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeAccountObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "照片入册数据统计接口", notes = "照片入册数据统计接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "workOrderPickID", value = "选片记录ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "attachmentID", value = "照片id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "String") })
	@RequestMapping(value = "/accountProduct.json", method = RequestMethod.POST)
	public String accountProduct(@RequestBody SingleRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();

		PageResponse<OrderProductDO> response = new PageResponse<OrderProductDO>();
		ResultDO resultDO = workPhotoProductService.account(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((List<OrderProductDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
			response.setComment((String) resultDO.getModel(ResultDO.SECOND_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeProductPage(response, PLANINTEXT);
	}

	@ApiOperation(value = "进入选片", notes = "照片入册数据统计接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "workOrderPickID", value = "选片记录ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "source", value = "片源:0-源片;2-修调片;", required = true, dataType = "Integer") })
	@RequestMapping(value = "/startPick.json", method = RequestMethod.POST)
	public String startPick(@RequestBody SingleRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();

		SingleResponse<WorkOrderPickDO> response = new SingleResponse<WorkOrderPickDO>();
		ResultDO resultDO = workOrderPickService.startPick(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((WorkOrderPickDO) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodePickObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "查询待制作商品详情", notes = "入册商品详情（生成制作单时使用）")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "Integer") })
	@RequestMapping(value = "/pickDetail.json", method = RequestMethod.POST)
	public String pickDetail(@RequestBody QueryRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();

		SingleResponse<WorkPickDetailDO> response = new SingleResponse<WorkPickDetailDO>();
		ResultDO resultDO = workPhotoProductService.pickDetail(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((WorkPickDetailDO) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeDetailObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "统计所有订单商品的入册照片数量及入底数量", notes = "统计所有商品的入册入底数据，提供给订单模块，更新订单相关数据")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "销售业务单号", required = true, dataType = "Integer") })
	@RequestMapping(value = "/test.json", method = RequestMethod.POST)
	public String test(@RequestBody SingleRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();

		SingleResponse<WorkPhotoPickDO> response = new SingleResponse<WorkPhotoPickDO>();
		ResultDO resultDO = workPhotoProductService.accountPick(domain.getWorkOrderID(), domain.getBusinessNo());
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((WorkPhotoPickDO) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodePhotoPickObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "查询是否已发送设计制作单", notes = "查询是否已发送设计制作单")
	@ApiImplicitParam(name = "workOrderPickID", value = "加选记录ID", required = true, dataType = "Integer")
	@RequestMapping(value = "/checkSend.json", method = RequestMethod.POST)
	public String checkSend(@RequestBody SingleRequest<WorkDesignOrderDO> request) {

		WorkDesignOrderDO domain = request.getData();

		SingleResponse<WorkDesignOrderDO> response = new SingleResponse<WorkDesignOrderDO>();
		ResultDO resultDO = workDesignOrderService.checkSend(domain.getWorkOrderPickID());
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((WorkDesignOrderDO) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeDesignObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "提交设计制作单", notes = "提交设计制作单")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "workOrderPickID", value = "加选记录ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "checkDesignDateStr", value = "计划看设计时间", required = true, dataType = "String"),
			@ApiImplicitParam(name = "deliveryDateStr", value = "计划取件时间", required = true, dataType = "String"),
			@ApiImplicitParam(name = "comment", value = "备注", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isUrgent", value = "是否加急", required = true, dataType = "Integer") })
	@RequestMapping(value = "/commitDesign.json", method = RequestMethod.POST)
	public String commitDesign(@RequestBody SingleRequest<WorkDesignOrderDO> request) {

		WorkDesignOrderDO domain = request.getData();

		SingleResponse<WorkPhotoPickDO> response = new SingleResponse<WorkPhotoPickDO>();
		ResultDO resultDO = workDesignOrderService.add(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((WorkPhotoPickDO) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodePhotoPickObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "查询订单商品列表（测试用）", notes = "查询订单商品列表（测试用）")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessNo", value = "工单业务单号", required = true, dataType = "String") })
	@RequestMapping(value = "/queryProduct.json", method = RequestMethod.POST)
	public String queryProduct(@RequestBody QueryRequest<WorkPhotoProductDO> request) {

		WorkPhotoProductDO domain = request.getData();
		PageResponse<OrderProductDO> response = new PageResponse<OrderProductDO>();
		ResultDO resultDO = workPhotoProductService.queryProduct(domain);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			List<OrderProductDO> list = (List<OrderProductDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY);
			list.remove(list.size() - 1);
			response.setData(list);
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodeProductPage(response, PLANINTEXT);
	}

}
